$(function() {
	initialValue();
});

function provinceChange(province) {
	$('#searchReslut').html("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
	$('#allCitySelect').empty();
	$.post('territory/allCity', {
		parentId : province
	}, function(data) {
		$(data).each(
				function(index, currData) {
					console.info(currData.province);
					if(index==0){
						cityChange(currData.code);
					}
					$("#allCitySelect").append(
							"<option value='" + currData.code + "'>"
									+ currData.city + "</option>");
				});
	});
}

function cityChange(city) {
	$('#searchReslut').html("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
	$('#allCountrySelect').empty();
	$.post('territory/allCountry', {
		code : city
	}, function(data) {
		$(data).each(
				function(index, currData) {
					$("#allCountrySelect").append(
							"<option value='" + currData.country + "'>"
									+ currData.country + "</option>");
				});
	});

}

function areaSearchButtonClick() {
	if ($('#allCountrySelect').val() == '未选择'
			|| $('#allCountrySelect').val() == null) {
		$('#searchReslut').html("选择正确的区域");
	} else {
		$.post('territory/isCovered', {
			name : $('#allCountrySelect').val()
		}, function(data) {
			if (data) {
				$('#searchReslut').html("这个地区已经覆盖");
			} else {
				$('#searchReslut').html("这个地区还没有覆盖");
			}
		});
	}
}
function initialValue() {
	$.post('territory/allProvince', {
		level : 1
	}, function(data) {
		$(data).each(
				function(index, currData) {
					$("#allProvinceSelect").append(
							"<option value='" + currData.code + "'>"
									+ currData.province + "</option>");
						if(index==0){
							provinceChange(currData.code);
						}
				});
	});
}